package com.fitsoftwareprocess.mobimap.dto;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import ULT.LocateConvert;
import android.R.bool;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Point;

public class MapInfoEx extends MapInfo
    {
        public int MapSource; //0: Google, 1: Local
        public int MapType;
        public Coordinate CoordinateCenter;
        public Point MapCenter;

        public String GetFullPath()
        {
            String name ;
            //= String.Empty;
            if(MapSource == 0)
                name=String.format("{0}_{1}_{2}_{3}.png", MapType, _zoom, _tile.x, _tile.y);
            else
                name = String.format("{0}_{1}_{2}.png", _zoom, _tile.x, _tile.y);
            String path = pathCombine(_mapStore, name);
            return path;
        }

        public boolean CheckExist()
        {
            File file;
            file= new File (get_FullPath()); 
            return file.exists();
        }

        public byte[] ConvertToByte() throws FileNotFoundException
        {
        	byte[] data ;
        	String filepath = get_FullPath();
        	File imagefile = new File(filepath + "icon.png");
        	FileInputStream fis ;
        	
        	fis= new FileInputStream(imagefile);;
    	
    		Bitmap bi = BitmapFactory.decodeStream(fis);
    		ByteArrayOutputStream baos = new ByteArrayOutputStream();
    	    	bi.compress(Bitmap.CompressFormat.PNG, 100, baos);
        	data= baos.toByteArray();
        	return data;
        }

        public void GlobalToMap()
        {
            MapCenter = LocateConvert.ToPoint(CoordinateCenter, _zoom);
        }
    }

